package com.daedalus.File.Serialization;

import java.io.Serializable;

public class Shitesi implements Serializable{

	private String name;
	private double payment;
	private double percentage;
	private double[] sales;
	int no_sales;
	
	public Shitesi(String emri, double rroga, double perqindja){
		setName(emri);
		setPayment(rroga);
		setPercentage(perqindja);
		sales=new double[1000];
		no_sales=0;
	}
	
	public Shitesi(){
		this("I panjohur",0.0,0.0);
	}
	
	public void setName(String n){
		name=n;
	}
	public void setPayment(double p){
		payment=p>0.0?p:0.0;
	}
	public void setPercentage(double per){
		percentage=per>0.0&&per<1.0?per:0.0;
	}
	public void addSale(double amount){
		sales[no_sales]=amount;
		no_sales++;
	}
	
	public String getName(){
		return name;
	}
	public double getPayment(){
		return payment;
	}
	public double getPercentage(){
		return percentage;
	}
	public double getEarnings(){
		return payment+percentage*getTotalSales();
	}
	public double[] getSales(){
		return sales;
	}
	public void printSales(){
		System.out.printf("%-15s %-15s\n","Njesia","Vlera");
		for(int i=0;i<no_sales;i++)
			System.out.printf("\n %-15d %-15.2f",i+1,sales[i]);
	}
	public double getTotalSales(){
		double total=0.0;
		for(int i=0;i<no_sales;i++)
			total+=sales[i];
		return total;
	}
	
	public String toString(){
		return String.format(" Emri: %s \n Rroga Baze: %.2f \n Shitje : %d \n Vlera totale e shitjeve: %.2f \n \n Totali i te ardhurave: %.2f\n\n",
				getName(),getPayment(),no_sales,getTotalSales(),getEarnings());
	}
}
